package until;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class diffChecker {

    public static void main(String[] args) {
        String file1Path = "parser.txt"; // 第一个文件的路径
        String file2Path = "testfile.txt"; // 第二个文件的路径
        String outputFilePath = "difference_1.txt"; // 输出文件的路径

        try (BufferedReader reader1 = new BufferedReader(new FileReader(file1Path));
             BufferedReader reader2 = new BufferedReader(new FileReader(file2Path));
             BufferedWriter writer = new BufferedWriter(new FileWriter(outputFilePath))) {

            String line1 = reader1.readLine();
            String line2 = reader2.readLine();
            int lineNumber = 1;

            while (line1 != null || line2 != null) {
                if (line1 == null || line2 == null || !line1.equals(line2)) {
                    writer.write("Line " + lineNumber + ":\n");
                    if (line1 != null) {
                        writer.write("  File1: " + line1 + "\n");
                    } else {
                        writer.write("  File1: (empty)\n");
                    }
                    if (line2 != null) {
                        writer.write("  File2: " + line2 + "\n");
                    } else {
                        writer.write("  File2: (empty)\n");
                    }
                }

                line1 = reader1.readLine();
                line2 = reader2.readLine();
                lineNumber++;
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}